<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="root"></div>
</body>
<script>
    const el = document.querySelector("#root");
    getUserList();
    function getUserList(){
        const xhr = new XMLHttpRequest();
        xhr.responseType = "json";
        xhr.open("get","http://127.0.0.1:8090/userList");
        xhr.send();
        xhr.onload = function(){
            el.innerHTML = xhr.response.map(info=>(`
            <a href="javascript:;" onclick="sendVote('${info.id}')">${info.username}(${info.voteNum})</a><hr/>
        `)).join("")
        }

    }


    function sendVote(id){
        const xhr = new XMLHttpRequest();
        xhr.open("get","http://127.0.0.1:8090/sendVote/"+id);
        xhr.send();
        xhr.onload = function(){
            getUserList();
        }
    }
</script>
</html>